<?php
namespace app\api\controller;
use app\api\model\Comment as CommentModel;
class Comment extends Controller
{
    public function getMovCommentList($query){
        $model=new CommentModel();
        $condition['type']=1;
        $condition['content'] =array('like',"%$query%");
        $userList=$model->where($condition)->select();
        return $this->renderSuccess($userList,'获取列表成功');
    }
    public function getMusCommentList($query){
        $model=new CommentModel();
        $condition['type']=2;
        $condition['content'] =array('like',"%$query%");
        $userList=$model->where($condition)->select();
        return $this->renderSuccess($userList,'获取列表成功');
    }
    public function getCommentbyMovie($Id){
        $model=new CommentModel();
        $comment=$model->where(['Id'=>$Id])->select();
        return $this->renderSuccess($comment, '查找成功');
    }
    public function getMovCommentbyUser($uid){
        $model=new CommentModel();
        $comment=$model->where(['uid'=>$uid,'type'=>1])->select();
        return $this->renderSuccess($comment, '查找成功');
    }
    public function getMusCommentbyUser($uid){
        $model=new CommentModel();
        $comment=$model->where(['uid'=>$uid,'type'=>2])->select();
        return $this->renderSuccess($comment, '查找成功');
    }
public function MovieComment(){
    $model=new CommentModel();
    $movie=$this->request->param();
    $movie['type']=1;
    empty($movie['time'])?$movie['time']=date('Y-m-d h:i:s', time()):$movie['time'];
    $com=$model->allowField(['Id','uid','content','score','type','time'])->save($movie);
    if($com){
        $new_com = $model->where(['Comid' => $model->getLastInsID()])->find();
        return $this->renderSuccess($new_com, '添加成功');
    }else {
        return $this->renderError('添加失败');
    }
}
    public function MusicListComment(){
        $model=new CommentModel();
        $music=$this->request->param();
        $music['type']=2;
        empty($music['time'])?$music['time']=date('Y-m-d h:i', time()):$music['time'];
        var_dump($music['time']);
        $com=$model->allowField(['Id','uid','content','type','time'])->save($music);
        if($com){
            $new_com = $model->where(['Comid' => $model->getLastInsID()])->find();
            return $this->renderSuccess($new_com, '添加成功');
        }else {
            return $this->renderError('添加失败');
        }
    }
    public function del($id)
    {
        if (CommentModel::destroy($id)) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }
}
